import axios from 'axios';
import * as contants from './constants';
import {fromJS} from "immutable";

const changeHomeData=(result)=>({
    type :contants.CHANGE_HOME_DATA,
    topicList: result.topicList,
    articleList:result.articleList,
    recommendList:result.recommendList
});
const addHomeList=(list,page)=>({
    type :contants.ADD_HOME_LIST,
    list:fromJS(list),
    nextPage:fromJS(page)
});

export const getHomeInfo=()=>{
    return (dispatch)=>{
        axios.get('/api/home.json').then((res)=>{
            const result=res.data.data;
            dispatch(changeHomeData(result))
        })
    }
};
export const getMoreList=(page)=>{
    return (dispatch)=>{
        axios.get('/api/homeList.json?page='+page).then((res)=>{
            const result=res.data.data;
            dispatch(addHomeList(result,page+1))
        })
    }
};
export const toggleTopShow=(show)=>({
  type:contants.TOGGLE_TOP_SHOW,
    show
});